<!DOCTYPE html>
<html class="x-admin-sm">

	<head>
		<meta charset="UTF-8">
		<title>欢迎页面-X-admin2.2</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<link rel="stylesheet" href="./css/font.css">
		<link rel="stylesheet" href="./css/xadmin.css">
		<link rel="stylesheet" href="css/global.css"/>
		<script src="./lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="./js/xadmin.js"></script>
		<!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
		<script src="js/jquery.min.js"></script>
		<script src="js/jquery.cookie.js"></script>
	</head>

	<body>
		<div class="x-nav">
			<span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
			<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
				<i class="layui-icon layui-icon-refresh" style="line-height:30px">刷新</i></a>
		</div>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15" id="app">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-body ">
							<div class="layui-card-header" id="div1">
								<button class="layui-btn" @click='sys_add()'><i class="layui-icon"></i>创建用户</button>
							</div>
							<form class="layui-form layui-col-space5">
								<div class="layui-inline layui-show-xs-block">
									<input type="text" id="name" name="name" placeholder="登录名/E-MAIL" autocomplete="off" class="layui-input">
								</div>
								<div class="layui-inline layui-show-xs-block">
									<button class="layui-btn" type="button" @click="mohu()" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
								</div>
								<button class="layui-btn" lay-filter="add" lay-submit="" type="reset">
                                                   清空
                      </button>
							</form>
						</div>

						<div class="layui-card-body ">
							<form method="get">
								<table class="layui-table layui-form">
									<thead>
										<tr>
											<th>登录名</th>
											<th>姓名</th>
											<th>E_MAIL</th>
											<th>电话号</th>
											<th>创建时间</th>
											<th>最后登录时间</th>
											<th>最后登录IP</th>
											<th>状态</th>
											<th>删除状态</th>
											<th>操作</th>
									</thead>
									<tr v-for="(obj, index) in pageArr">
										<td> {{ obj.loginName }} </td>
										<td> {{ obj.userName }} </td>
										<td> {{ obj.email }} </td>
										<td> {{ obj.tel }} </td>
										<td> {{ obj.createTime }} </td>
										<td> {{ obj.lastLoginTime }} </td>
										<td> {{ obj.lastLoginIp }} </td>
										<td v-if="obj.status==1"> 冻结 </td>
										<td v-if="obj.status==0"> 正常 </td>
										<td> {{ obj.flag }} </td>
										<td> 
											<a title='查看日志' @click="member_open(obj.userId)" href='javascript:;'><i class='layui-icon'>&#xe63c;</i></a> 
											<a title='修改密码' @click="updatepwd(obj.userId, obj.loginName)" href='javascript:;'><i class='layui-icon'>&#xe631;</i></a>
											<a title='冻结'   @click="member_stop(obj.userId, obj.status)" href='javascript:;'><i class='layui-icon'>&#xe601;</i></a>
											<a title='编辑' @click="member_update(obj.userId)" href='javascript:;'> <i class='layui-icon'>&#xe642;</i> </a>
											<a title='删除' @click="member_del(this, obj.userId)" href='javascript:;'><i class='layui-icon'>&#xe640;</i> </a>
										</td>
									</tr>
								</table>
							</form>
						</div>
					</div>
				</div>
				<div class="paging" id="pageHelper">
							<a href="#" @click="first" title="">首</a>
							<a id="backpage" @click="last" href="#" title="">&lt;</a>
							<a id="nextpage" href="#" @click="next" title="">&gt;</a>
							<a href="#" @click="end" title="">末</a>
								<div class="layui-inline layui-show-xs-block">
									<input type="text" id="num" size="1" style="height: 25px;"  class="layui-input">
								</div> 
								<a href="#" @click="tz" title="">跳转</a>
							 共：<span id="sp">{{this.totalPage}}</span>页
							<div class="clear"></div>
						</div>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="./js/jquery.min.js"></script>
	<!--引入Vue的js 开发环境版本., 包含了有帮助的命令行警告-->
	<script src="./js/vue.min.js"></script>
	<script type="text/javascript" src="js/vue.js"></script>
	<script src="js/axios.min.js"></script>
	<script type="text/javascript" src="js/jquery.cookie.js"></script>
	<script src="js/pageHelp.js"></script>
	<script>
		var rid = $.cookie("rId");
		const app = new Vue({
			el: "#app",
			data: { //数据
				sysSubject: [],
				page: 1, //当前页
				totalPage: 0, //总页数
				pageArr: [] //中间值，循环所用的数据
			},
			methods: { //事件方法
				//首页
					first: function() {
						this.page = 1;
						this.pageArr = pageHelp(this.sysSubject, 5, 1);
					},
					//上一页
					last: function() {
						this.page = this.page - 1;
						if(this.page <= 1) {
							layer.msg("已经第一页了")
							this.page=1;
						}
						this.pageArr = pageHelp(this.sysSubject, 5, this.page);
					},
					//下一页
					next: function() {
						this.page = this.page + 1;
						console.log(this.page)
						if(this.page >= this.totalPage) {
						layer.msg("已经最后一页了")
							this.page=this.totalPage;
						}
						this.pageArr = pageHelp(this.sysSubject, 5, this.page);
					},
					//末页
					end: function() {
						this.page = this.totalPage;
						this.pageArr = pageHelp(this.sysSubject, 5, this.totalPage)
					},
					
					//跳转页面
					tz: function() {
						var num=$("#num").val();
						if(num>this.totalPage||num<1){
						layer.msg("请输入正确的页数")	
						$("#num").val("");
						
						}
						this.pageArr = pageHelp(this.sysSubject, 5, num)
						$("#num").val("");
					},
				 sys_add(){
				 	if(rid==1){
				 		xadmin.open('添加用户','./sysuser-add.html',600,500);
				 	}else {
						layer.confirm('无操作权限，请联系管理员！')
					}
				 },
				
				member_open(id) {
					$.cookie("id", id);
					location.href = "log-list.html";
				},
				updatepwd(id, loginName) {
					if(rid == 1) {
						$.cookie("id", id);
						$.cookie("loginName", loginName);
						xadmin.open('修改密码', "sysuser-updatePwd.html", 600, 300);
					} else {
						layer.confirm('无操作权限，请联系管理员！')
		
					}
				},
				member_stop(id, status) {
					if(rid == 1) {
						if(status == 0) {
							layer.confirm('确认要冻结吗？',
								function(index) {
									$.ajax({
										type: "post",
										url: "http://localhost:9095/admin/sysUser/updateStatus",
										async: true,
										headers:{
        	 			                     "token2":$.cookie("token2")
        	 		                         },
										data: {
											"userId": id,
											"status": status,
										},
										success(msg) {
											location.reload();
										}
									});
									layer.msg('已冻结!', {
										icon: 1,
										time: 1000
									});
								});
						} else {
							layer.confirm('确认要恢复吗？',
								function(index) {
									$.ajax({
										type: "post",
										url: "http://localhost:9095/admin/sysUser/updateStatus",
										async: true,
										headers: {
									"token2": $.cookie("token2")
								},
										data: {
											"userId": id,
											"status": status,
										},
										success(msg) {
											location.reload();
										}
									});
									layer.msg('已恢复!', {
										icon: 1,
										time: 1000
									});
								});
						}
					} else {
						layer.confirm('无操作权限，请联系管理员！',
							)
					}
				},
				member_update(id) {
					if(rid == 1) {
						$.cookie("id", id);
						xadmin.open('用户编辑', "sysuser-update.html", 600, 500);
					} else {
						layer.confirm('无操作权限，请联系管理员！',
							)
					}
				},
				member_del(obj, id) {
					if(rid == 1) {
		
						layer.confirm('确认要删除吗？',
							function(index) {
								//发异步删除数据
								$.ajax({
									type: "post",
									url: "http://localhost:9095/admin/sysUser/upPassword",
									async: true,
									headers: {
									"token2": $.cookie("token2")
								},
									data: {
										"id": id,
									},
									success(msg) {
										//$(obj).parent().parent().remove();
										location.reload();
									}
								});
		
								layer.msg('已删除!', {
									icon: 1,
									time: 1000
								});
							});
					} else {
						layer.confirm('无操作权限，请联系管理员！',
							)
					}
				},
				mohu(){
					var keyWord=$("#name").val();
					let _this = this;
					console.log(keyWord);
					$.ajax({
						type:"get",
						url:"http://localhost:9095/admin/sysUser/list",
						data:{
							"keyWord" :keyWord
						},
						headers: {
									"token2": $.cookie("token2")
								},
						async:true,
						success(msg){
							_this.sysSubject = msg.data;
							_this.pageArr = _this.sysSubject; //数据长度
							_this.totalPage = Math.ceil(_this.pageArr.length / 5) //总页数
							_this.first();
						}
					});
				}
			},
			created() { //页面加载
				let _this = this;
				axios.defaults.headers.common["token2"] = $.cookie("token2");
				axios.get("http://localhost:9095/admin/sysUser/list").then(function(response) {
					console.log(response.data);
					_this.sysSubject = response.data.data;
					_this.pageArr = _this.sysSubject; //数据长度
					_this.totalPage = Math.ceil(_this.pageArr.length / 5) //总页数
					_this.first();
				});
			}

		})

		layui.use(['laydate', 'form'], function() {
			var laydate = layui.laydate;
			var form = layui.form;

			//执行一个laydate实例
			laydate.render({
				elem: '#start' //指定元素
			});

			//执行一个laydate实例
			laydate.render({
				elem: '#end' //指定元素
			});
		});
	</script>
	<script>
		var _hmt = _hmt || [];
		(function() {
			var hm = document.createElement("script");
			hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
			var s = document.getElementsByTagName("script")[0];
			s.parentNode.insertBefore(hm, s);
		})();
	</script>

</html>